//*********************************************
//  This is Geant4 Template
//                                  author:Qian
//

#ifndef MyOpticalPhotonAnalysis_h
#define MyOpticalPhotonAnalysis_h 1

#include "G4RunManager.hh"
#include "G4UnitsTable.hh"
#include "G4SystemOfUnits.hh"
#include "G4Event.hh"
#include "PGGeneratorList.hh"
#include "MyBasedAnalysis.hh"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#include "TROOT.h"
#include "TString.h"
#pragma GCC diagnostic pop

#define MAXOPPHOTON 2000

#include <iomanip>

class TFile;
class TTree;
class TNtuple;
class MyDetectorConstruction;
class MyEvtAction;
class MyRunAction;
class MyBasedAnalysis;

class MyOpticalPhotonAnalysis : public MyBasedAnalysis
{
public:
    MyOpticalPhotonAnalysis();
    ~MyOpticalPhotonAnalysis();

    void BeginOfEventAction(const G4Event *evt);
    void EndOfEventAction(const G4Event *evt);

    void BeginOfRunAction();
    void EndOfRunAction();

    G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack);
    void SteppingAction(const G4Step *aStep);
    void PreTrackingAction(const G4Track *aTrack);
    void PostTrackingAction(const G4Track *aTrack);

    inline void SetFileName(G4String fname) { fFileName = fname; }
    inline void Activated() { active = true; }
    inline void Deactivated() { active = false; }
    inline bool IsActivated() { return active; }

    inline void SetDetectorConstruction(MyDetectorConstruction *det) { fDetector = det; }
    inline void SetRunAction(MyRunAction *run) { fRunAction = run; }
    inline void SetEvtAction(MyEvtAction *evt) { fEvtAction = evt; }
    
private:
    bool active = false;

    PGGenerator* fPGGenerator;
    PGGeneratorList* fPGGeneratorList;
    Long64_t fTotalEventNumber;

    //ROOT file
    G4String fFileName;
    TFile *fRootFp;

    //Tree for Event
    TTree *fTree;
    Int_t fPGTypeFlag;
    Double_t fTruthEnergy;
    Double_t fTruthPos[3];
    Double_t fTruthMomDir[3];
    Int_t fNumOfOpPhoton;
    Double_t fPhotonEnergy[MAXOPPHOTON];
    Double_t fPhotonCatchTime[MAXOPPHOTON];
    Double_t fPhotonPos[MAXOPPHOTON][3];
    Double_t fPhotonMomDir[MAXOPPHOTON][3];

    MyDetectorConstruction *fDetector;
    MyRunAction *fRunAction;
    MyEvtAction *fEvtAction;
};

#endif